package com.boliq.demo.adapter;

import android.view.ViewGroup;

import com.boliq.demo.Demo2Fragment;
import com.boliq.demo.Demo3Fragment;
import com.boliq.demo.DemoFragment;
import com.boliq.demo.FragmentActivity;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class MainVpAdapter extends FragmentPagerAdapter {


    private final int PAGER_COUNT = 3;
    private DemoFragment myFragment1 = null;
    private Demo2Fragment myFragment2 = null;
    private Demo3Fragment myFragment3 = null;
    public MainVpAdapter(FragmentManager fm) {
        super(fm);
        myFragment1 = new DemoFragment();
        myFragment2 = new Demo2Fragment();
        myFragment3 = new Demo3Fragment();

    }


    @Override
    public int getCount() {
        return PAGER_COUNT;
    }
    @Override
    public Object instantiateItem(ViewGroup vg, int position) {
        return super.instantiateItem(vg, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        System.out.println("position Destory" + position);
        super.destroyItem(container, position, object);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case FragmentActivity.PAGE_ONE:
                fragment = myFragment1;
                break;
            case FragmentActivity.PAGE_TWO:
                fragment = myFragment2;
                break;
            case FragmentActivity.PAGE_THREE:
                fragment = myFragment3;
                break;

        }
        return fragment;
    }
}
